#!/usr/bin/php
<?
// $Id: console.php 61 2010-11-26 23:16:01Z MartinS $

die ("Don't activate this script; you'll break something.");
foreach ($argv as $arg) {
  if (substr($arg, 0, 2) == "--") {
    $argument[substr($arg, 2)] = 1;
  } elseif (substr($arg, 0, 1) == "-") {
    $oArg = substr($arg, 1);
  } else {
    switch ($oArg) {
      case "P": case "A": case "T":
        $argument["pages"][] = $arg;
        break;
      default:
      $argument[$oArg][] = $arg;
    }
  }
}

// Script copied from console-doibot.php but not modified; of no use yet!


error_reporting(E_ALL^E_NOTICE);
$accountSuffix='_1'; // This must be specified before including boot.php
$htmlOutput = false; // This must be specified before including boot.php
include("boot.php");
$editInitiator = '[c' . (revisionID() + 1) . '&beta;]';
$ON = true; // Override later if necessary

print "\nGetting a list of all taxa: ";
$all_pages = getPrefixIndex("Taxonomy/", 10, "Taxonomy/Inc");
print count($all_pages) . " pages in total";
print "\nGetting taxa that already use the template: ";
$already_ok = whatTranscludes("Don't edit this line 1");
print count($already_ok) . " taxa already use template:Don't edit this line.\n";

foreach ($all_pages as $page) {
  $title = $page;
  if (!in_array($title, $already_ok)) {
    $start_text = (getRawWikitext($title));
    $lines = explode("\n", $start_text);
    if ($lines[2]) {
      $lines[0] = "{{Don't edit this line {{{machine code|}}}|{{{1}}}";
      $final_text = implode("\n", $lines);
      print (write($title, $final_text, $editInitiator . "Use [[Template:Don't edit this line]] (per [[WP:BRFA/Taxobot 5|Taxobot task 5]])")
              ? "\nWritten to $title\n"
              : "\nCouldn't write to $title\n");
      $written++;
      sleep(5);
    } else {
      print "\nFewer than 2 lines; probably a redirect?";
    }
  } else print ".";
}

die ("\n\n === stop here. === \n");

#$STOP = true;
$ON = false; // Uncomment this line to set the bot onto the Zandbox, switched off.

$page = "User:taxobot/Sandbox";  // Leave this line as is.  It'll be over-written when the bot is turned on.
if ($ON) {

}
include("expand.php");// i.e. GO!

print "\n Done. \n";
